package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorDemo {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("你");
        c.add("是");
        c.add("谁");
        c.add("呀");
        Iterator<String> it = c.iterator();//获取c的迭代器
        while (it.hasNext()){//询问下一个元素是否存在
           String s = it.next();//指针下移，并获取指针指向元素
           it.remove();//删除指针指向的元素
            System.out.println(s);
        }
        System.out.println(c.size());
    }
}
